package com.business.weixin.controller.gen;

import com.business.system.common.base.BaseController;
import com.business.weixin.util.SignUtil;
import com.business.weixin.util.Weixin;
import com.business.weixin.util.WeixinService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

@Controller
@RequestMapping("weixinController")
public class WeixinController extends BaseController{

	@Autowired
	public WeixinService weixinService;

    @GetMapping("/wechat")
	public void wechatGet(HttpServletRequest request,
						  HttpServletResponse response,
						  @RequestParam(value = "signature") String signature,
						  @RequestParam(value = "timestamp") String timestamp,
						  @RequestParam(value = "nonce") String nonce,
						  @RequestParam(value = "echostr") String echostr) {
		String token= Weixin.token;
		if (SignUtil.checkSignature(token, signature, timestamp, nonce)) {
			try {
				response.getWriter().print(echostr);
			} catch (Exception e) {
				// TODO Auto-generated catch block
				e.printStackTrace();
			}
		}
	}
}
